/* Copyright (c) 2007  Peter Palotas
 *  
 *  This software is provided 'as-is', without any express or implied
 *  warranty. In no event will the authors be held liable for any damages
 *  arising from the use of this software.
 *  
 *  Permission is granted to anyone to use this software for any purpose,
 *  including commercial applications, and to alter it and redistribute it
 *  freely, subject to the following restrictions:
 *  
 *      1. The origin of this software must not be misrepresented; you must not
 *      claim that you wrote the original software. If you use this software
 *      in a product, an acknowledgment in the product documentation would be
 *      appreciated but is not required.
 *  
 *      2. Altered source versions must be plainly marked as such, and must not be
 *      misrepresented as being the original software.
 *  
 *      3. This notice may not be removed or altered from any source
 *      distribution.
 *  
 *  
 *  $Id: OptionGroup.cs 19 2007-08-15 13:14:32Z palotas $
 */
using System;
using SCG = System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using C5;

namespace Plossum.CommandLine
{
    internal class OptionGroup
    {
        public OptionGroup(string id, string name, string description, OptionGroupRequirement require, bool requireExplicitAssignment, SCG.IComparer<string> keyComparer)
        {
            Debug.Assert(!String.IsNullOrEmpty(id));
            Debug.Assert(keyComparer != null);

            mId = id;
            mName = name;
            mDescription = description;
            mRequire = require;
            mOptions = new TreeDictionary<string, Option>(keyComparer);
            mRequireExplicitAssignment = requireExplicitAssignment;
        }

        #region Public properties

        public string Id
        {
            get { return mId; }
        }

        public OptionGroupRequirement Require
        {
            get { return mRequire; }
        }

        public string Description
        {
            get { return mDescription; }
            set { mDescription = value; }
        }
	
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }

        public IDictionary<string, Option> Options
        {
            get { return mOptions; }
        }

        public bool RequireExplicitAssignment
        {
            get { return mRequireExplicitAssignment; }
        }

        public string GetOptionNamesAsString()
        {
            StringBuilder names = new StringBuilder();
            bool isFirst = true;
            foreach (KeyValuePair<string, Option> entry in mOptions)
            {
                if (!isFirst)
                    names.Append(", ");
                else
                    isFirst = false;


                names.Append('\"');
                names.Append(entry.Key);
                names.Append('\"');
            }
            return names.ToString();
        }
        #endregion

        #region Private fields

        private string mId;
        private string mName;
        private OptionGroupRequirement mRequire;
        private string mDescription;
        private IDictionary<string, Option> mOptions;
        private bool mRequireExplicitAssignment;

        #endregion
    }
}
